﻿using AdinZ.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;


/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/4/18 16:30:07
*
* */
namespace Novel.Sys.Dal
{
    public class novel_recharge
    {
        public int Add(Model.novel_recharge model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("INSERT INTO [novel_recharge] ([uid], [payment], [paytime], [type],[intor],[ordId]) VALUES (");
            strSql.Append("@uid,@payment,@paytime,@type,@intor,@ordId");
            strSql.Append(");select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@uid", SqlDbType.Int),
                    new SqlParameter("@payment", SqlDbType.Float),
                    new SqlParameter("@paytime", SqlDbType.DateTime),
                    new SqlParameter("@type", SqlDbType.NVarChar),
                    new SqlParameter("@intor", SqlDbType.NVarChar)  ,
                    new SqlParameter("@ordId", SqlDbType.NVarChar)                   };
            parameters[0].Value = model.Uid;
            parameters[1].Value = model.Payment;
            parameters[2].Value = model.PayTime;
            parameters[3].Value = model.Type;
            parameters[4].Value = model.Intor;
            parameters[5].Value = model.OrdID;

            object obj = DbHelpers.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }


        public bool Exists(int UID, string OrdId)
        {
            string sql = "select count(1) from [novel_recharge] where uid='" + UID + "' and ordId='"+OrdId+"'";
            return DbHelpers.Exists(sql);
        }
    
    
    
    }
}
